﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class CategoryParrentDAO
    {
        DBService _db = null;
        public CategoryParrentDAO(String ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public DataTable GetMenuParrent()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from CategoryParrent", false, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public CategoryParrent GetMenuParrent_ById(int IDCateParrent)
        {
            CategoryParrent MenuParrent = new CategoryParrent();
            try
            {
                DataTable dt = null;
                dt = _db.ExeSP_DataTable("select * from CategoryParrent where IDCateParrent = @IDCateParrent",
                    new string[] { "@IDCateParrent"},
                    new object[] { IDCateParrent }, CommandType.Text);
                foreach (DataRow dr in dt.Rows)
                {
                    MenuParrent.IDCateParrent = IDCateParrent;
                    MenuParrent.CategoryParrName = dr["CategoryParrName"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return MenuParrent;
        }

        public DataTable InsUp_MenuParrent(CategoryParrent MenuParrent, int mode)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_CategoryParrent_InsUp",
                    new string[] { "@IDCateParrent", "@CategoryParrName", "@mode" },
                    new object[] {MenuParrent.IDCateParrent, MenuParrent.CategoryParrName, mode }, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
    }
}
